<?php
namespace M\Action;
use Common\Model;
class IndexAction extends BaseAction{
	public function _initialize() {
        parent::_initialize();
        $this->_ad = D('ad')->cache(true, 10 * 60);
        $this->_mod = D('items')->cache(true, 5 * 60);
		$this->_pddmod = D('pdditems')->cache(true, 10 * 60);
		C('DATA_CACHE_TIME',C('yh_site_cachetime'));
    }
	
 private function _alert_adv(){
        if(cookie("alertad")!="yes"){
                cookie("alertad", "yes", 3600 * 12);  
                $ad=M('ad')->where('status=4 and add_time = 0')->find();
                return $ad;
      }
    }

  public function  index(){
  $this->assign('alertadv',$this->_alert_adv());
$ad = $this->_ad->where(array('status'=>'1','add_time'=>0))->order('id desc')->select();
$this->assign('ad_list', $ad);
$where=array(
'coupon_discount'=>array('gt',10),
'sold_quantity'=>array('gt',1000)
);
$pdditems=$this->_pddmod->field('goods_id,goods_name,goods_thumbnail_url,sold_quantity,min_group_price,coupon_discount,min_normal_price')->where($where)->order('id desc')->limit(8)->select();
$this->assign('pdditems',$pdditems);

  $today_wh['pass'] = '1';
  $today_wh['isshow'] = '1';	
  $today_wh['status'] = 'underway';
  $today_str = mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"));
  $tomorr_str = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
  $today_wh['add_time'] = array(
    array(
      'egt',
      $today_str
      ),
    array(
      'elt',
      $tomorr_str
      )
    );
    //零时取消 where 语句
  $today_list=$this->_mod->field('id,pic_url,title,commission_rate,coupon_price,price,quan,shop_type,volume,add_time')->order('is_commend desc,id desc,volume desc')->limit(5)->select();
  $this->assign('today_list',$today_list);	


$where['quan']=array('gt',20);
$items_list = $this->_mod->field('id,pic_url,title,coupon_price,commission_rate,price,quan,shop_type,volume,add_time')->order('ordid asc,id desc')->limit(60)->select();	
if($items_list){
$today=date('Ymd');
$goodslist=array();
foreach($items_list as $k=>$v){
$goodslist[$k]['id']=$v['id'];
$goodslist[$k]['pic_url']=$v['pic_url'];
$goodslist[$k]['title']=$v['title'];
$goodslist[$k]['commission_rate']=$v['commission_rate'];
$goodslist[$k]['coupon_price']=$v['coupon_price'];
$goodslist[$k]['price']=$v['price'];
$goodslist[$k]['quan']=$v['quan'];
$goodslist[$k]['shop_type']=$v['shop_type'];
$goodslist[$k]['volume']=$v['volume'];	
if($today==date('Ymd',$v['add_time'])){
$goodslist[$k]['is_new']=1;	
}else{
$goodslist[$k]['is_new']=0;		
}
if(C('APP_SUB_DOMAIN_DEPLOY')){
$goodslist[$k]['linkurl']=U('/item/',array('id'=>$v['id']));
}else{
$goodslist[$k]['linkurl']=U('item/index',array('id'=>$v['id']));
}
	
}
}

$this->assign('list',$goodslist);



$this->_config_seo(C('yh_seo_config.index'));

	$this->display();  	
}


public function cate() {
$ad = $this->_ad->where(array('status'=>'1'))->order('id desc')->select();
$this->assign('ad_list', $ad);
$cateinfo = $this->_cate_mod->where(array('status'=>1))->select();
$article_list =$this->_article->where('status=1')
            ->field('id,title')
            ->order('ordid asc,id desc')
            ->limit(6)
            ->select();
$this->assign('article_list', $article_list);
	$this->_config_seo(C('yh_seo_config.index'));

	$this->display('list/index');  	
}



}